Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
lodash.get
Advanced tools
The lodash.get package is a method from the Lodash library that allows for safe access to nested object properties. It helps in avoiding errors when querying for deeply nested properties in an object that may or may not exist.
Accessing Nested Object Properties
Safely access nested object properties using a string path.
const object = { 'a': [{ 'b': { 'c': 3 } }] };
const value = _.get(object, 'a[0].b.c');
console.log(value); // => 3
Default Values
Provide a default value if the resolved value is undefined.
const object = { 'a': [{ 'b': { 'c': 3 } }] };
const value = _.get(object, 'a[0].b.d', 'default');
console.log(value); // => 'default'
Accessing Properties with Dynamic Paths
Use an array to specify the path for properties, allowing for dynamic path construction.
const object = { 'a': [{ 'b': { 'c': 3 } }] };
const path = ['a', '0', 'b', 'c'];
const value = _.get(object, path);
console.log(value); // => 3
object-path is similar to lodash.get in that it provides access to nested object properties. It offers a similar API but does not have the same level of utility functions that lodash provides.
dlv is a tiny utility similar to lodash.get for safely accessing deep properties of objects. It is smaller in size compared to lodash.get, which might be beneficial for performance-sensitive applications.
dot-prop allows for similar functionality to lodash.get with the ability to get, set, or delete properties from a nested object using a dot path. It differs in API and does not provide the same default value feature as lodash.get.
The lodash method _.get
exported as a Node.js module.
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.get
In Node.js:
var get = require('lodash.get');
See the documentation or package source for more details.
FAQs
The lodash method `_.get` exported as a module.
The npm package lodash.get receives a total of 12,095,779 weekly downloads. As such, lodash.get popularity was classified as popular.
We found that lodash.get demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.